package qldc.pm.qlktcsdldc.service.persistence;

import com.liferay.portal.kernel.cache.CacheRegistryUtil;
import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
import com.liferay.portal.kernel.dao.orm.FinderPath;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.InstanceFactory;
import com.liferay.portal.kernel.util.OrderByComparator;
import com.liferay.portal.kernel.util.PropsKeys;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.UnmodifiableList;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.ModelListener;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;

import qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException;
import qldc.pm.qlktcsdldc.model.DanhMucSoBanNganh_TruongCongDan;
import qldc.pm.qlktcsdldc.model.impl.DanhMucSoBanNganh_TruongCongDanImpl;
import qldc.pm.qlktcsdldc.model.impl.DanhMucSoBanNganh_TruongCongDanModelImpl;
import qldc.pm.qlktcsdldc.service.persistence.DanhMucSoBanNganh_TruongCongDanPersistence;

import java.io.Serializable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * The persistence implementation for the danh muc so ban nganh_ truong cong dan service.
 *
 * <p>
 * Caching information and settings can be found in <code>portal.properties</code>
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see DanhMucSoBanNganh_TruongCongDanPersistence
 * @see DanhMucSoBanNganh_TruongCongDanUtil
 * @generated
 */
public class DanhMucSoBanNganh_TruongCongDanPersistenceImpl
    extends BasePersistenceImpl<DanhMucSoBanNganh_TruongCongDan>
    implements DanhMucSoBanNganh_TruongCongDanPersistence {
    /*
     * NOTE FOR DEVELOPERS:
     *
     * Never modify or reference this class directly. Always use {@link DanhMucSoBanNganh_TruongCongDanUtil} to access the danh muc so ban nganh_ truong cong dan persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
     */
    public static final String FINDER_CLASS_NAME_ENTITY = DanhMucSoBanNganh_TruongCongDanImpl.class.getName();
    public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List1";
    public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
        ".List2";
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanModelImpl.FINDER_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanModelImpl.FINDER_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
    public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll",
            new String[0]);
    public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_IDQLKT_DANHMUCSOBANNGANH =
        new FinderPath(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanModelImpl.FINDER_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanImpl.class,
            FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
            "findByIDQLKT_DanhMucSoBanNganh",
            new String[] {
                Long.class.getName(),
                
            Integer.class.getName(), Integer.class.getName(),
                OrderByComparator.class.getName()
            });
    public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_IDQLKT_DANHMUCSOBANNGANH =
        new FinderPath(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanModelImpl.FINDER_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanImpl.class,
            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "findByIDQLKT_DanhMucSoBanNganh",
            new String[] { Long.class.getName() },
            DanhMucSoBanNganh_TruongCongDanModelImpl.IDQLKT_DANHMUCSOBANNGANH_COLUMN_BITMASK);
    public static final FinderPath FINDER_PATH_COUNT_BY_IDQLKT_DANHMUCSOBANNGANH =
        new FinderPath(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanModelImpl.FINDER_CACHE_ENABLED,
            Long.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
            "countByIDQLKT_DanhMucSoBanNganh",
            new String[] { Long.class.getName() });
    private static final String _FINDER_COLUMN_IDQLKT_DANHMUCSOBANNGANH_IDQLKT_DANHMUCSOBANNGANH_2 =
        "danhMucSoBanNganh_TruongCongDan.IDQLKT_DanhMucSoBanNganh = ?";
    private static final String _SQL_SELECT_DANHMUCSOBANNGANH_TRUONGCONGDAN = "SELECT danhMucSoBanNganh_TruongCongDan FROM DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan";
    private static final String _SQL_SELECT_DANHMUCSOBANNGANH_TRUONGCONGDAN_WHERE =
        "SELECT danhMucSoBanNganh_TruongCongDan FROM DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan WHERE ";
    private static final String _SQL_COUNT_DANHMUCSOBANNGANH_TRUONGCONGDAN = "SELECT COUNT(danhMucSoBanNganh_TruongCongDan) FROM DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan";
    private static final String _SQL_COUNT_DANHMUCSOBANNGANH_TRUONGCONGDAN_WHERE =
        "SELECT COUNT(danhMucSoBanNganh_TruongCongDan) FROM DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan WHERE ";
    private static final String _ORDER_BY_ENTITY_ALIAS = "danhMucSoBanNganh_TruongCongDan.";
    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No DanhMucSoBanNganh_TruongCongDan exists with the primary key ";
    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No DanhMucSoBanNganh_TruongCongDan exists with the key {";
    private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = GetterUtil.getBoolean(PropsUtil.get(
                PropsKeys.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE));
    private static Log _log = LogFactoryUtil.getLog(DanhMucSoBanNganh_TruongCongDanPersistenceImpl.class);
    private static DanhMucSoBanNganh_TruongCongDan _nullDanhMucSoBanNganh_TruongCongDan =
        new DanhMucSoBanNganh_TruongCongDanImpl() {
            @Override
            public Object clone() {
                return this;
            }

            @Override
            public CacheModel<DanhMucSoBanNganh_TruongCongDan> toCacheModel() {
                return _nullDanhMucSoBanNganh_TruongCongDanCacheModel;
            }
        };

    private static CacheModel<DanhMucSoBanNganh_TruongCongDan> _nullDanhMucSoBanNganh_TruongCongDanCacheModel =
        new CacheModel<DanhMucSoBanNganh_TruongCongDan>() {
            @Override
            public DanhMucSoBanNganh_TruongCongDan toEntityModel() {
                return _nullDanhMucSoBanNganh_TruongCongDan;
            }
        };

    public DanhMucSoBanNganh_TruongCongDanPersistenceImpl() {
        setModelClass(DanhMucSoBanNganh_TruongCongDan.class);
    }

    /**
     * Returns all the danh muc so ban nganh_ truong cong dans where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @return the matching danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<DanhMucSoBanNganh_TruongCongDan> findByIDQLKT_DanhMucSoBanNganh(
        long IDQLKT_DanhMucSoBanNganh) throws SystemException {
        return findByIDQLKT_DanhMucSoBanNganh(IDQLKT_DanhMucSoBanNganh,
            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the danh muc so ban nganh_ truong cong dans where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.qlktcsdldc.model.impl.DanhMucSoBanNganh_TruongCongDanModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @param start the lower bound of the range of danh muc so ban nganh_ truong cong dans
     * @param end the upper bound of the range of danh muc so ban nganh_ truong cong dans (not inclusive)
     * @return the range of matching danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<DanhMucSoBanNganh_TruongCongDan> findByIDQLKT_DanhMucSoBanNganh(
        long IDQLKT_DanhMucSoBanNganh, int start, int end)
        throws SystemException {
        return findByIDQLKT_DanhMucSoBanNganh(IDQLKT_DanhMucSoBanNganh, start,
            end, null);
    }

    /**
     * Returns an ordered range of all the danh muc so ban nganh_ truong cong dans where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.qlktcsdldc.model.impl.DanhMucSoBanNganh_TruongCongDanModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @param start the lower bound of the range of danh muc so ban nganh_ truong cong dans
     * @param end the upper bound of the range of danh muc so ban nganh_ truong cong dans (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of matching danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<DanhMucSoBanNganh_TruongCongDan> findByIDQLKT_DanhMucSoBanNganh(
        long IDQLKT_DanhMucSoBanNganh, int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_IDQLKT_DANHMUCSOBANNGANH;
            finderArgs = new Object[] { IDQLKT_DanhMucSoBanNganh };
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_IDQLKT_DANHMUCSOBANNGANH;
            finderArgs = new Object[] {
                    IDQLKT_DanhMucSoBanNganh,
                    
                    start, end, orderByComparator
                };
        }

        List<DanhMucSoBanNganh_TruongCongDan> list = (List<DanhMucSoBanNganh_TruongCongDan>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if ((list != null) && !list.isEmpty()) {
            for (DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan : list) {
                if ((IDQLKT_DanhMucSoBanNganh != danhMucSoBanNganh_TruongCongDan.getIDQLKT_DanhMucSoBanNganh())) {
                    list = null;

                    break;
                }
            }
        }

        if (list == null) {
            StringBundler query = null;

            if (orderByComparator != null) {
                query = new StringBundler(3 +
                        (orderByComparator.getOrderByFields().length * 3));
            } else {
                query = new StringBundler(3);
            }

            query.append(_SQL_SELECT_DANHMUCSOBANNGANH_TRUONGCONGDAN_WHERE);

            query.append(_FINDER_COLUMN_IDQLKT_DANHMUCSOBANNGANH_IDQLKT_DANHMUCSOBANNGANH_2);

            if (orderByComparator != null) {
                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);
            } else
             if (pagination) {
                query.append(DanhMucSoBanNganh_TruongCongDanModelImpl.ORDER_BY_JPQL);
            }

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(IDQLKT_DanhMucSoBanNganh);

                if (!pagination) {
                    list = (List<DanhMucSoBanNganh_TruongCongDan>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<DanhMucSoBanNganh_TruongCongDan>(list);
                } else {
                    list = (List<DanhMucSoBanNganh_TruongCongDan>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Returns the first danh muc so ban nganh_ truong cong dan in the ordered set where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching danh muc so ban nganh_ truong cong dan
     * @throws qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException if a matching danh muc so ban nganh_ truong cong dan could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan findByIDQLKT_DanhMucSoBanNganh_First(
        long IDQLKT_DanhMucSoBanNganh, OrderByComparator orderByComparator)
        throws NoSuchDanhMucSoBanNganh_TruongCongDanException, SystemException {
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan = fetchByIDQLKT_DanhMucSoBanNganh_First(IDQLKT_DanhMucSoBanNganh,
                orderByComparator);

        if (danhMucSoBanNganh_TruongCongDan != null) {
            return danhMucSoBanNganh_TruongCongDan;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("IDQLKT_DanhMucSoBanNganh=");
        msg.append(IDQLKT_DanhMucSoBanNganh);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchDanhMucSoBanNganh_TruongCongDanException(msg.toString());
    }

    /**
     * Returns the first danh muc so ban nganh_ truong cong dan in the ordered set where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the first matching danh muc so ban nganh_ truong cong dan, or <code>null</code> if a matching danh muc so ban nganh_ truong cong dan could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan fetchByIDQLKT_DanhMucSoBanNganh_First(
        long IDQLKT_DanhMucSoBanNganh, OrderByComparator orderByComparator)
        throws SystemException {
        List<DanhMucSoBanNganh_TruongCongDan> list = findByIDQLKT_DanhMucSoBanNganh(IDQLKT_DanhMucSoBanNganh,
                0, 1, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the last danh muc so ban nganh_ truong cong dan in the ordered set where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching danh muc so ban nganh_ truong cong dan
     * @throws qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException if a matching danh muc so ban nganh_ truong cong dan could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan findByIDQLKT_DanhMucSoBanNganh_Last(
        long IDQLKT_DanhMucSoBanNganh, OrderByComparator orderByComparator)
        throws NoSuchDanhMucSoBanNganh_TruongCongDanException, SystemException {
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan = fetchByIDQLKT_DanhMucSoBanNganh_Last(IDQLKT_DanhMucSoBanNganh,
                orderByComparator);

        if (danhMucSoBanNganh_TruongCongDan != null) {
            return danhMucSoBanNganh_TruongCongDan;
        }

        StringBundler msg = new StringBundler(4);

        msg.append(_NO_SUCH_ENTITY_WITH_KEY);

        msg.append("IDQLKT_DanhMucSoBanNganh=");
        msg.append(IDQLKT_DanhMucSoBanNganh);

        msg.append(StringPool.CLOSE_CURLY_BRACE);

        throw new NoSuchDanhMucSoBanNganh_TruongCongDanException(msg.toString());
    }

    /**
     * Returns the last danh muc so ban nganh_ truong cong dan in the ordered set where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the last matching danh muc so ban nganh_ truong cong dan, or <code>null</code> if a matching danh muc so ban nganh_ truong cong dan could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan fetchByIDQLKT_DanhMucSoBanNganh_Last(
        long IDQLKT_DanhMucSoBanNganh, OrderByComparator orderByComparator)
        throws SystemException {
        int count = countByIDQLKT_DanhMucSoBanNganh(IDQLKT_DanhMucSoBanNganh);

        if (count == 0) {
            return null;
        }

        List<DanhMucSoBanNganh_TruongCongDan> list = findByIDQLKT_DanhMucSoBanNganh(IDQLKT_DanhMucSoBanNganh,
                count - 1, count, orderByComparator);

        if (!list.isEmpty()) {
            return list.get(0);
        }

        return null;
    }

    /**
     * Returns the danh muc so ban nganh_ truong cong dans before and after the current danh muc so ban nganh_ truong cong dan in the ordered set where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * @param IDDanhMucSoBanNganh_TruongCongDan the primary key of the current danh muc so ban nganh_ truong cong dan
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
     * @return the previous, current, and next danh muc so ban nganh_ truong cong dan
     * @throws qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException if a danh muc so ban nganh_ truong cong dan with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan[] findByIDQLKT_DanhMucSoBanNganh_PrevAndNext(
        long IDDanhMucSoBanNganh_TruongCongDan, long IDQLKT_DanhMucSoBanNganh,
        OrderByComparator orderByComparator)
        throws NoSuchDanhMucSoBanNganh_TruongCongDanException, SystemException {
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan = findByPrimaryKey(IDDanhMucSoBanNganh_TruongCongDan);

        Session session = null;

        try {
            session = openSession();

            DanhMucSoBanNganh_TruongCongDan[] array = new DanhMucSoBanNganh_TruongCongDanImpl[3];

            array[0] = getByIDQLKT_DanhMucSoBanNganh_PrevAndNext(session,
                    danhMucSoBanNganh_TruongCongDan, IDQLKT_DanhMucSoBanNganh,
                    orderByComparator, true);

            array[1] = danhMucSoBanNganh_TruongCongDan;

            array[2] = getByIDQLKT_DanhMucSoBanNganh_PrevAndNext(session,
                    danhMucSoBanNganh_TruongCongDan, IDQLKT_DanhMucSoBanNganh,
                    orderByComparator, false);

            return array;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    protected DanhMucSoBanNganh_TruongCongDan getByIDQLKT_DanhMucSoBanNganh_PrevAndNext(
        Session session,
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan,
        long IDQLKT_DanhMucSoBanNganh, OrderByComparator orderByComparator,
        boolean previous) {
        StringBundler query = null;

        if (orderByComparator != null) {
            query = new StringBundler(6 +
                    (orderByComparator.getOrderByFields().length * 6));
        } else {
            query = new StringBundler(3);
        }

        query.append(_SQL_SELECT_DANHMUCSOBANNGANH_TRUONGCONGDAN_WHERE);

        query.append(_FINDER_COLUMN_IDQLKT_DANHMUCSOBANNGANH_IDQLKT_DANHMUCSOBANNGANH_2);

        if (orderByComparator != null) {
            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();

            if (orderByConditionFields.length > 0) {
                query.append(WHERE_AND);
            }

            for (int i = 0; i < orderByConditionFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByConditionFields[i]);

                if ((i + 1) < orderByConditionFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
                    } else {
                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(WHERE_GREATER_THAN);
                    } else {
                        query.append(WHERE_LESSER_THAN);
                    }
                }
            }

            query.append(ORDER_BY_CLAUSE);

            String[] orderByFields = orderByComparator.getOrderByFields();

            for (int i = 0; i < orderByFields.length; i++) {
                query.append(_ORDER_BY_ENTITY_ALIAS);
                query.append(orderByFields[i]);

                if ((i + 1) < orderByFields.length) {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC_HAS_NEXT);
                    } else {
                        query.append(ORDER_BY_DESC_HAS_NEXT);
                    }
                } else {
                    if (orderByComparator.isAscending() ^ previous) {
                        query.append(ORDER_BY_ASC);
                    } else {
                        query.append(ORDER_BY_DESC);
                    }
                }
            }
        } else {
            query.append(DanhMucSoBanNganh_TruongCongDanModelImpl.ORDER_BY_JPQL);
        }

        String sql = query.toString();

        Query q = session.createQuery(sql);

        q.setFirstResult(0);
        q.setMaxResults(2);

        QueryPos qPos = QueryPos.getInstance(q);

        qPos.add(IDQLKT_DanhMucSoBanNganh);

        if (orderByComparator != null) {
            Object[] values = orderByComparator.getOrderByConditionValues(danhMucSoBanNganh_TruongCongDan);

            for (Object value : values) {
                qPos.add(value);
            }
        }

        List<DanhMucSoBanNganh_TruongCongDan> list = q.list();

        if (list.size() == 2) {
            return list.get(1);
        } else {
            return null;
        }
    }

    /**
     * Removes all the danh muc so ban nganh_ truong cong dans where IDQLKT_DanhMucSoBanNganh = &#63; from the database.
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeByIDQLKT_DanhMucSoBanNganh(long IDQLKT_DanhMucSoBanNganh)
        throws SystemException {
        for (DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan : findByIDQLKT_DanhMucSoBanNganh(
                IDQLKT_DanhMucSoBanNganh, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
                null)) {
            remove(danhMucSoBanNganh_TruongCongDan);
        }
    }

    /**
     * Returns the number of danh muc so ban nganh_ truong cong dans where IDQLKT_DanhMucSoBanNganh = &#63;.
     *
     * @param IDQLKT_DanhMucSoBanNganh the i d q l k t_ danh muc so ban nganh
     * @return the number of matching danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countByIDQLKT_DanhMucSoBanNganh(long IDQLKT_DanhMucSoBanNganh)
        throws SystemException {
        FinderPath finderPath = FINDER_PATH_COUNT_BY_IDQLKT_DANHMUCSOBANNGANH;

        Object[] finderArgs = new Object[] { IDQLKT_DanhMucSoBanNganh };

        Long count = (Long) FinderCacheUtil.getResult(finderPath, finderArgs,
                this);

        if (count == null) {
            StringBundler query = new StringBundler(2);

            query.append(_SQL_COUNT_DANHMUCSOBANNGANH_TRUONGCONGDAN_WHERE);

            query.append(_FINDER_COLUMN_IDQLKT_DANHMUCSOBANNGANH_IDQLKT_DANHMUCSOBANNGANH_2);

            String sql = query.toString();

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                QueryPos qPos = QueryPos.getInstance(q);

                qPos.add(IDQLKT_DanhMucSoBanNganh);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(finderPath, finderArgs, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Caches the danh muc so ban nganh_ truong cong dan in the entity cache if it is enabled.
     *
     * @param danhMucSoBanNganh_TruongCongDan the danh muc so ban nganh_ truong cong dan
     */
    @Override
    public void cacheResult(
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan) {
        EntityCacheUtil.putResult(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanImpl.class,
            danhMucSoBanNganh_TruongCongDan.getPrimaryKey(),
            danhMucSoBanNganh_TruongCongDan);

        danhMucSoBanNganh_TruongCongDan.resetOriginalValues();
    }

    /**
     * Caches the danh muc so ban nganh_ truong cong dans in the entity cache if it is enabled.
     *
     * @param danhMucSoBanNganh_TruongCongDans the danh muc so ban nganh_ truong cong dans
     */
    @Override
    public void cacheResult(
        List<DanhMucSoBanNganh_TruongCongDan> danhMucSoBanNganh_TruongCongDans) {
        for (DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan : danhMucSoBanNganh_TruongCongDans) {
            if (EntityCacheUtil.getResult(
                        DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
                        DanhMucSoBanNganh_TruongCongDanImpl.class,
                        danhMucSoBanNganh_TruongCongDan.getPrimaryKey()) == null) {
                cacheResult(danhMucSoBanNganh_TruongCongDan);
            } else {
                danhMucSoBanNganh_TruongCongDan.resetOriginalValues();
            }
        }
    }

    /**
     * Clears the cache for all danh muc so ban nganh_ truong cong dans.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache() {
        if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
            CacheRegistryUtil.clear(DanhMucSoBanNganh_TruongCongDanImpl.class.getName());
        }

        EntityCacheUtil.clearCache(DanhMucSoBanNganh_TruongCongDanImpl.class.getName());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    /**
     * Clears the cache for the danh muc so ban nganh_ truong cong dan.
     *
     * <p>
     * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
     * </p>
     */
    @Override
    public void clearCache(
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan) {
        EntityCacheUtil.removeResult(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanImpl.class,
            danhMucSoBanNganh_TruongCongDan.getPrimaryKey());

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }

    @Override
    public void clearCache(
        List<DanhMucSoBanNganh_TruongCongDan> danhMucSoBanNganh_TruongCongDans) {
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);

        for (DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan : danhMucSoBanNganh_TruongCongDans) {
            EntityCacheUtil.removeResult(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
                DanhMucSoBanNganh_TruongCongDanImpl.class,
                danhMucSoBanNganh_TruongCongDan.getPrimaryKey());
        }
    }

    /**
     * Creates a new danh muc so ban nganh_ truong cong dan with the primary key. Does not add the danh muc so ban nganh_ truong cong dan to the database.
     *
     * @param IDDanhMucSoBanNganh_TruongCongDan the primary key for the new danh muc so ban nganh_ truong cong dan
     * @return the new danh muc so ban nganh_ truong cong dan
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan create(
        long IDDanhMucSoBanNganh_TruongCongDan) {
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan = new DanhMucSoBanNganh_TruongCongDanImpl();

        danhMucSoBanNganh_TruongCongDan.setNew(true);
        danhMucSoBanNganh_TruongCongDan.setPrimaryKey(IDDanhMucSoBanNganh_TruongCongDan);

        return danhMucSoBanNganh_TruongCongDan;
    }

    /**
     * Removes the danh muc so ban nganh_ truong cong dan with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param IDDanhMucSoBanNganh_TruongCongDan the primary key of the danh muc so ban nganh_ truong cong dan
     * @return the danh muc so ban nganh_ truong cong dan that was removed
     * @throws qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException if a danh muc so ban nganh_ truong cong dan with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan remove(
        long IDDanhMucSoBanNganh_TruongCongDan)
        throws NoSuchDanhMucSoBanNganh_TruongCongDanException, SystemException {
        return remove((Serializable) IDDanhMucSoBanNganh_TruongCongDan);
    }

    /**
     * Removes the danh muc so ban nganh_ truong cong dan with the primary key from the database. Also notifies the appropriate model listeners.
     *
     * @param primaryKey the primary key of the danh muc so ban nganh_ truong cong dan
     * @return the danh muc so ban nganh_ truong cong dan that was removed
     * @throws qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException if a danh muc so ban nganh_ truong cong dan with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan remove(Serializable primaryKey)
        throws NoSuchDanhMucSoBanNganh_TruongCongDanException, SystemException {
        Session session = null;

        try {
            session = openSession();

            DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan = (DanhMucSoBanNganh_TruongCongDan) session.get(DanhMucSoBanNganh_TruongCongDanImpl.class,
                    primaryKey);

            if (danhMucSoBanNganh_TruongCongDan == null) {
                if (_log.isWarnEnabled()) {
                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
                }

                throw new NoSuchDanhMucSoBanNganh_TruongCongDanException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                    primaryKey);
            }

            return remove(danhMucSoBanNganh_TruongCongDan);
        } catch (NoSuchDanhMucSoBanNganh_TruongCongDanException nsee) {
            throw nsee;
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }

    @Override
    protected DanhMucSoBanNganh_TruongCongDan removeImpl(
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan)
        throws SystemException {
        danhMucSoBanNganh_TruongCongDan = toUnwrappedModel(danhMucSoBanNganh_TruongCongDan);

        Session session = null;

        try {
            session = openSession();

            if (!session.contains(danhMucSoBanNganh_TruongCongDan)) {
                danhMucSoBanNganh_TruongCongDan = (DanhMucSoBanNganh_TruongCongDan) session.get(DanhMucSoBanNganh_TruongCongDanImpl.class,
                        danhMucSoBanNganh_TruongCongDan.getPrimaryKeyObj());
            }

            if (danhMucSoBanNganh_TruongCongDan != null) {
                session.delete(danhMucSoBanNganh_TruongCongDan);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        if (danhMucSoBanNganh_TruongCongDan != null) {
            clearCache(danhMucSoBanNganh_TruongCongDan);
        }

        return danhMucSoBanNganh_TruongCongDan;
    }

    @Override
    public DanhMucSoBanNganh_TruongCongDan updateImpl(
        qldc.pm.qlktcsdldc.model.DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan)
        throws SystemException {
        danhMucSoBanNganh_TruongCongDan = toUnwrappedModel(danhMucSoBanNganh_TruongCongDan);

        boolean isNew = danhMucSoBanNganh_TruongCongDan.isNew();

        DanhMucSoBanNganh_TruongCongDanModelImpl danhMucSoBanNganh_TruongCongDanModelImpl =
            (DanhMucSoBanNganh_TruongCongDanModelImpl) danhMucSoBanNganh_TruongCongDan;

        Session session = null;

        try {
            session = openSession();

            if (danhMucSoBanNganh_TruongCongDan.isNew()) {
                session.save(danhMucSoBanNganh_TruongCongDan);

                danhMucSoBanNganh_TruongCongDan.setNew(false);
            } else {
                session.merge(danhMucSoBanNganh_TruongCongDan);
            }
        } catch (Exception e) {
            throw processException(e);
        } finally {
            closeSession(session);
        }

        FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

        if (isNew ||
                !DanhMucSoBanNganh_TruongCongDanModelImpl.COLUMN_BITMASK_ENABLED) {
            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
        }
        else {
            if ((danhMucSoBanNganh_TruongCongDanModelImpl.getColumnBitmask() &
                    FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_IDQLKT_DANHMUCSOBANNGANH.getColumnBitmask()) != 0) {
                Object[] args = new Object[] {
                        danhMucSoBanNganh_TruongCongDanModelImpl.getOriginalIDQLKT_DanhMucSoBanNganh()
                    };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_IDQLKT_DANHMUCSOBANNGANH,
                    args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_IDQLKT_DANHMUCSOBANNGANH,
                    args);

                args = new Object[] {
                        danhMucSoBanNganh_TruongCongDanModelImpl.getIDQLKT_DanhMucSoBanNganh()
                    };

                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_IDQLKT_DANHMUCSOBANNGANH,
                    args);
                FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_IDQLKT_DANHMUCSOBANNGANH,
                    args);
            }
        }

        EntityCacheUtil.putResult(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
            DanhMucSoBanNganh_TruongCongDanImpl.class,
            danhMucSoBanNganh_TruongCongDan.getPrimaryKey(),
            danhMucSoBanNganh_TruongCongDan);

        return danhMucSoBanNganh_TruongCongDan;
    }

    protected DanhMucSoBanNganh_TruongCongDan toUnwrappedModel(
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan) {
        if (danhMucSoBanNganh_TruongCongDan instanceof DanhMucSoBanNganh_TruongCongDanImpl) {
            return danhMucSoBanNganh_TruongCongDan;
        }

        DanhMucSoBanNganh_TruongCongDanImpl danhMucSoBanNganh_TruongCongDanImpl = new DanhMucSoBanNganh_TruongCongDanImpl();

        danhMucSoBanNganh_TruongCongDanImpl.setNew(danhMucSoBanNganh_TruongCongDan.isNew());
        danhMucSoBanNganh_TruongCongDanImpl.setPrimaryKey(danhMucSoBanNganh_TruongCongDan.getPrimaryKey());

        danhMucSoBanNganh_TruongCongDanImpl.setIDDanhMucSoBanNganh_TruongCongDan(danhMucSoBanNganh_TruongCongDan.getIDDanhMucSoBanNganh_TruongCongDan());
        danhMucSoBanNganh_TruongCongDanImpl.setGroupId(danhMucSoBanNganh_TruongCongDan.getGroupId());
        danhMucSoBanNganh_TruongCongDanImpl.setCompanyId(danhMucSoBanNganh_TruongCongDan.getCompanyId());
        danhMucSoBanNganh_TruongCongDanImpl.setUserId(danhMucSoBanNganh_TruongCongDan.getUserId());
        danhMucSoBanNganh_TruongCongDanImpl.setUserName(danhMucSoBanNganh_TruongCongDan.getUserName());
        danhMucSoBanNganh_TruongCongDanImpl.setCreateDate(danhMucSoBanNganh_TruongCongDan.getCreateDate());
        danhMucSoBanNganh_TruongCongDanImpl.setModifiedDate(danhMucSoBanNganh_TruongCongDan.getModifiedDate());
        danhMucSoBanNganh_TruongCongDanImpl.setIDQLKT_DanhMucSoBanNganh(danhMucSoBanNganh_TruongCongDan.getIDQLKT_DanhMucSoBanNganh());
        danhMucSoBanNganh_TruongCongDanImpl.setIDDMDC_TruongCongDan(danhMucSoBanNganh_TruongCongDan.getIDDMDC_TruongCongDan());

        return danhMucSoBanNganh_TruongCongDanImpl;
    }

    /**
     * Returns the danh muc so ban nganh_ truong cong dan with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
     *
     * @param primaryKey the primary key of the danh muc so ban nganh_ truong cong dan
     * @return the danh muc so ban nganh_ truong cong dan
     * @throws qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException if a danh muc so ban nganh_ truong cong dan with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan findByPrimaryKey(
        Serializable primaryKey)
        throws NoSuchDanhMucSoBanNganh_TruongCongDanException, SystemException {
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan = fetchByPrimaryKey(primaryKey);

        if (danhMucSoBanNganh_TruongCongDan == null) {
            if (_log.isWarnEnabled()) {
                _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
            }

            throw new NoSuchDanhMucSoBanNganh_TruongCongDanException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
                primaryKey);
        }

        return danhMucSoBanNganh_TruongCongDan;
    }

    /**
     * Returns the danh muc so ban nganh_ truong cong dan with the primary key or throws a {@link qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException} if it could not be found.
     *
     * @param IDDanhMucSoBanNganh_TruongCongDan the primary key of the danh muc so ban nganh_ truong cong dan
     * @return the danh muc so ban nganh_ truong cong dan
     * @throws qldc.pm.qlktcsdldc.NoSuchDanhMucSoBanNganh_TruongCongDanException if a danh muc so ban nganh_ truong cong dan with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan findByPrimaryKey(
        long IDDanhMucSoBanNganh_TruongCongDan)
        throws NoSuchDanhMucSoBanNganh_TruongCongDanException, SystemException {
        return findByPrimaryKey((Serializable) IDDanhMucSoBanNganh_TruongCongDan);
    }

    /**
     * Returns the danh muc so ban nganh_ truong cong dan with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param primaryKey the primary key of the danh muc so ban nganh_ truong cong dan
     * @return the danh muc so ban nganh_ truong cong dan, or <code>null</code> if a danh muc so ban nganh_ truong cong dan with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan fetchByPrimaryKey(
        Serializable primaryKey) throws SystemException {
        DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan = (DanhMucSoBanNganh_TruongCongDan) EntityCacheUtil.getResult(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
                DanhMucSoBanNganh_TruongCongDanImpl.class, primaryKey);

        if (danhMucSoBanNganh_TruongCongDan == _nullDanhMucSoBanNganh_TruongCongDan) {
            return null;
        }

        if (danhMucSoBanNganh_TruongCongDan == null) {
            Session session = null;

            try {
                session = openSession();

                danhMucSoBanNganh_TruongCongDan = (DanhMucSoBanNganh_TruongCongDan) session.get(DanhMucSoBanNganh_TruongCongDanImpl.class,
                        primaryKey);

                if (danhMucSoBanNganh_TruongCongDan != null) {
                    cacheResult(danhMucSoBanNganh_TruongCongDan);
                } else {
                    EntityCacheUtil.putResult(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
                        DanhMucSoBanNganh_TruongCongDanImpl.class, primaryKey,
                        _nullDanhMucSoBanNganh_TruongCongDan);
                }
            } catch (Exception e) {
                EntityCacheUtil.removeResult(DanhMucSoBanNganh_TruongCongDanModelImpl.ENTITY_CACHE_ENABLED,
                    DanhMucSoBanNganh_TruongCongDanImpl.class, primaryKey);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return danhMucSoBanNganh_TruongCongDan;
    }

    /**
     * Returns the danh muc so ban nganh_ truong cong dan with the primary key or returns <code>null</code> if it could not be found.
     *
     * @param IDDanhMucSoBanNganh_TruongCongDan the primary key of the danh muc so ban nganh_ truong cong dan
     * @return the danh muc so ban nganh_ truong cong dan, or <code>null</code> if a danh muc so ban nganh_ truong cong dan with the primary key could not be found
     * @throws SystemException if a system exception occurred
     */
    @Override
    public DanhMucSoBanNganh_TruongCongDan fetchByPrimaryKey(
        long IDDanhMucSoBanNganh_TruongCongDan) throws SystemException {
        return fetchByPrimaryKey((Serializable) IDDanhMucSoBanNganh_TruongCongDan);
    }

    /**
     * Returns all the danh muc so ban nganh_ truong cong dans.
     *
     * @return the danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<DanhMucSoBanNganh_TruongCongDan> findAll()
        throws SystemException {
        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
    }

    /**
     * Returns a range of all the danh muc so ban nganh_ truong cong dans.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.qlktcsdldc.model.impl.DanhMucSoBanNganh_TruongCongDanModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of danh muc so ban nganh_ truong cong dans
     * @param end the upper bound of the range of danh muc so ban nganh_ truong cong dans (not inclusive)
     * @return the range of danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<DanhMucSoBanNganh_TruongCongDan> findAll(int start, int end)
        throws SystemException {
        return findAll(start, end, null);
    }

    /**
     * Returns an ordered range of all the danh muc so ban nganh_ truong cong dans.
     *
     * <p>
     * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link qldc.pm.qlktcsdldc.model.impl.DanhMucSoBanNganh_TruongCongDanModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
     * </p>
     *
     * @param start the lower bound of the range of danh muc so ban nganh_ truong cong dans
     * @param end the upper bound of the range of danh muc so ban nganh_ truong cong dans (not inclusive)
     * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
     * @return the ordered range of danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public List<DanhMucSoBanNganh_TruongCongDan> findAll(int start, int end,
        OrderByComparator orderByComparator) throws SystemException {
        boolean pagination = true;
        FinderPath finderPath = null;
        Object[] finderArgs = null;

        if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
                (orderByComparator == null)) {
            pagination = false;
            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
            finderArgs = FINDER_ARGS_EMPTY;
        } else {
            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
            finderArgs = new Object[] { start, end, orderByComparator };
        }

        List<DanhMucSoBanNganh_TruongCongDan> list = (List<DanhMucSoBanNganh_TruongCongDan>) FinderCacheUtil.getResult(finderPath,
                finderArgs, this);

        if (list == null) {
            StringBundler query = null;
            String sql = null;

            if (orderByComparator != null) {
                query = new StringBundler(2 +
                        (orderByComparator.getOrderByFields().length * 3));

                query.append(_SQL_SELECT_DANHMUCSOBANNGANH_TRUONGCONGDAN);

                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
                    orderByComparator);

                sql = query.toString();
            } else {
                sql = _SQL_SELECT_DANHMUCSOBANNGANH_TRUONGCONGDAN;

                if (pagination) {
                    sql = sql.concat(DanhMucSoBanNganh_TruongCongDanModelImpl.ORDER_BY_JPQL);
                }
            }

            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(sql);

                if (!pagination) {
                    list = (List<DanhMucSoBanNganh_TruongCongDan>) QueryUtil.list(q,
                            getDialect(), start, end, false);

                    Collections.sort(list);

                    list = new UnmodifiableList<DanhMucSoBanNganh_TruongCongDan>(list);
                } else {
                    list = (List<DanhMucSoBanNganh_TruongCongDan>) QueryUtil.list(q,
                            getDialect(), start, end);
                }

                cacheResult(list);

                FinderCacheUtil.putResult(finderPath, finderArgs, list);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(finderPath, finderArgs);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return list;
    }

    /**
     * Removes all the danh muc so ban nganh_ truong cong dans from the database.
     *
     * @throws SystemException if a system exception occurred
     */
    @Override
    public void removeAll() throws SystemException {
        for (DanhMucSoBanNganh_TruongCongDan danhMucSoBanNganh_TruongCongDan : findAll()) {
            remove(danhMucSoBanNganh_TruongCongDan);
        }
    }

    /**
     * Returns the number of danh muc so ban nganh_ truong cong dans.
     *
     * @return the number of danh muc so ban nganh_ truong cong dans
     * @throws SystemException if a system exception occurred
     */
    @Override
    public int countAll() throws SystemException {
        Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
                FINDER_ARGS_EMPTY, this);

        if (count == null) {
            Session session = null;

            try {
                session = openSession();

                Query q = session.createQuery(_SQL_COUNT_DANHMUCSOBANNGANH_TRUONGCONGDAN);

                count = (Long) q.uniqueResult();

                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY, count);
            } catch (Exception e) {
                FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
                    FINDER_ARGS_EMPTY);

                throw processException(e);
            } finally {
                closeSession(session);
            }
        }

        return count.intValue();
    }

    /**
     * Initializes the danh muc so ban nganh_ truong cong dan persistence.
     */
    public void afterPropertiesSet() {
        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
                    com.liferay.util.service.ServiceProps.get(
                        "value.object.listener.qldc.pm.qlktcsdldc.model.DanhMucSoBanNganh_TruongCongDan")));

        if (listenerClassNames.length > 0) {
            try {
                List<ModelListener<DanhMucSoBanNganh_TruongCongDan>> listenersList =
                    new ArrayList<ModelListener<DanhMucSoBanNganh_TruongCongDan>>();

                for (String listenerClassName : listenerClassNames) {
                    listenersList.add((ModelListener<DanhMucSoBanNganh_TruongCongDan>) InstanceFactory.newInstance(
                            getClassLoader(), listenerClassName));
                }

                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
            } catch (Exception e) {
                _log.error(e);
            }
        }
    }

    public void destroy() {
        EntityCacheUtil.removeCache(DanhMucSoBanNganh_TruongCongDanImpl.class.getName());
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
        FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    }
}
